// grzxm.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: '',
    dpxinxi: null,
    severUrl: '',
    beijing_url: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      dpxinxi: app.globalData.dpxinxi,
      // severUrl: app.globalData.severUrl,
      shop_name: app.globalData.shop_infos.FullName,
      beijing_url: app.globalData.shop_infos.Banner1,
      url_title: app.globalData._new_url,

    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  tohuiyuan: function () {
    wx.showModal({
      title: '温馨提示',
      content: '暂未发布',
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    that.setData({ shop_name: app.globalData.shop_infos.FullName, beijing_url: app.globalData.shop_infos.Banner1, })
    wx.request({
      url: app.globalData._new_url + 'MenuAPI/Member/GetEntityByOpenId',
      data: {
        openid: app.globalData.openId
      },
      method: 'POST',
      success: function (res) {
        console.log('hyzx', res)
        wx.setStorageSync('hy_info', res.data.entity)
        if (res.data.status == 0) {
          that.setData({
            url: '../hyzx/hyzx'
          })
        } else {
          that.setData({
            url: '../hyzxm/hyzxm'
          })
          app.globalData.NumberId = res.data.entity.Id
        }
      }
    })
  },
  getPhoneNumber: function (e) {
    console.log(e)
    if (e.detail.errMsg == 'getPhoneNumber:fail user deny') { } else {
      wx.request({
        url: app.globalData._new_url + 'MenuAPI/MessageTemplate/AuthorizeShopManager',
        data: {
          openId: app.globalData.openId,
          shopId: app.globalData.category_id,
          encryptedData: e.detail.encryptedData,
          iv: e.detail.iv,
          sessionKey: app.globalData.sessionKey
        },
        method: 'post',
        success: res => {
          if (res.data.status == 1) {
            wx.showModal({
              title: '温馨提示',
              content: '授权成功！',
              showCancel: false
            })
          }
        }
      })
    }
  },
  shouquan: function () {
    wx.showModal({
      title: '注意事项',
      content: '此授权功能仅对商户有效',
      success: res => {
        if (res.confirm) {
          this.getPhoneNumber()
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  onShareAppMessage: function () {
    return {
      title: app.globalData.dpxinxi.sname,
      path: '/pages/index/index',
      success: function (res) {
        // 分享成功
      }
    }
  },
  call: function () {

    wx.makePhoneCall({
      phoneNumber: app.globalData.shop_infos.Telephone + '' //仅为示例，并非真实的电话号码
    })
  },
  call2: function () {
    wx.makePhoneCall({
      phoneNumber: '4000245898' //仅为示例，并非真实的电话号码
    })
  }
})